<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo Yii::app()->name;?>后台管理</title>
<?php $this->renderPartial('/_include/_header');?>
</head>
<body class="view_index" id="view_index_School">
<script type="text/javascript">

</script>
<div style="padding:0 10px">
    <?php
if (!isset($rows)){
?>
    <table class="return-jump" border="0" cellspacing="0" cellpadding="0" width="" align="center" style="width:400px">
        <thead>
            <tr>
                <th class="jump-title">操作提示：<br>
                    <b><?php echo isset($title) ? $title : '操作成功！';?></b></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td class="jump-content icon-yes"><p><?php echo isset($content) ? $content : '稍后关闭页面，请稍等...';?></p></td>
            </tr>
        </tbody>
    </table>
    <script>

var api = art.dialog.open.api;
    setTimeout(function(){
		api.close();
	},1000);
</script>
    <?php
exit();
}
?>
    <table class="view-index-search mb-10" border="0" cellspacing="0" cellpadding="0" width="100%">
        <form class="view-index-form" method="post" action="<?php echo $this->createUrl('Moderator', array('forumid'=>$forumid));?>" enctype="multipart/form-data">
            <input type="hidden" class="input-text" id="YII_CSRF_TOKEN" name="YII_CSRF_TOKEN" value="<?php echo Yii::app()->request->csrfToken;?>">
            <input type="hidden" name="forumid" value="<?php echo $forumid?>" />
            <tr>
                <td class="search"><div class="div-search" style="margin:0px 0px"> 用户姓名：
                        <input class="input-text" value="<?php echo $keyword;?>" id="keyword" name="keyword" style="width:200px;"/>
                        <span class="view-index-batch">
                        <input id="submit_search" class="btn-button confirmSubmit" type="submit" value="搜索" name="submit_search" />
                        </span> </div></td>
            </tr>
        </form>
    </table>
    <table class="view-index-list" border="0" cellspacing="0" cellpadding="0" width="100%">
        <form id="adminer-form" class="view-index-form" method="post" action="<?php echo $this->createUrl('moderator', array('forumid'=>$forumid));?>" enctype="multipart/form-data">
            <input type="hidden" class="input-text" id="YII_CSRF_TOKEN" name="YII_CSRF_TOKEN" value="<?php echo Yii::app()->request->csrfToken;?>">
            <input type="hidden" name="forumid" value="<?php echo $forumid?>" />
            <thead>
                <tr>
                    <th>未加入版主</th>
                    <th>操作</th>
                    <th>已加入版主</th>
                </tr>
            </thead>
            <tr>
                <td><select id="selectL" name="selectL" multiple="multiple" style="width:240px; height:270px">
                        <?php
    if ($rows) foreach($rows as $k=>$v){
		echo '<option value="'.$v['userid'].'">'.$v['username'].'</option>';
}
    ?>
                    </select></td>
                <td align="center"><a id="toright" href="javascript:;" style="font-size:28px; font-family:'黑体'" title="添加">&gt;</a><br>
                    <br>
                    <a id="toleft" href="javascript:;" style="font-size:28px; font-family:'黑体'" title="移除">&lt;</a></td>
                <td><select id="selectR" name="checked_forumid[]" multiple="multiple" style="width:240px; height:270px">
                        <?php        
                        
			if($comm) foreach($comm as $k=>$v){
                                 
				echo '<option value="'.$v['userid'].'">'.$v['username'].'</option>';
				
			}
                        
		  ?>
                    </select></td>
            </tr>
            <tr>
                <td colspan="3" style=""><div class="pages" style="height:; padding:0px">
                        <?php $this->widget('CLinkPager',array(    
    'header'=>'',    
    'firstPageLabel' => '首页',    
    'lastPageLabel' => '末页',    
    'prevPageLabel' => '上一页',    
    'nextPageLabel' => '下一页',    
    'pages' => $pages,    
    'maxButtonCount'=>10    
    )    
    );
    ?>
                    </div></td>
            </tr>
        </form>
    </table>
</div>
<script>
function update(){
	var userid = [];
	$("#selectR option").each(function(){
		userid.push($(this).val());
	});

	$.getJSON("<?php echo $this->createUrl('setmoderator')?>", {forumid: '<?php echo $forumid?>',userid: userid.join(',')}, function(data) {
	  
		  
	});
	
}
function selected(){

	if($("#selectR option").length==0){
		alert('请选择');
		return false;
	}else{
		$("#selectR option").attr('selected', true);
	}
	$('#adminer-form').submit();	
}

    var api = art.dialog.open.api;
	//alert(api);

    //操作对话框
    api.button(
		{
			name: '确定',
			callback: function () {
			},
			focus: true
		},
		{
			name: '取消'
		}
		/*, 更多按钮.. */
	)
	// 锁屏
	.lock();
	
	$(function(){
	var leftSel = $("#selectL");
        var rightSel = $("#selectR");
	
	function isselected(v){
		var sel = false;
		rightSel.find("option").each(function(){
			if ($(this).val() == v){
				sel = true;
			}	
		});
		if ($("#selectR option").length > 4){
			alert('最多设置5个版主');
			return true;
		}
		return sel;
	}


	$("#toright").bind("click",function(){
		leftSel.find("option:selected").each(function(){
			var s = isselected($(this).val());
			if (!s){
			      $(this).remove().appendTo(rightSel);
            }
		});
		update();
	});
	$("#toleft").bind("click",function(){		
		rightSel.find("option:selected").each(function(){
			$(this).remove().appendTo(leftSel);

		});
		update();
	});
	leftSel.dblclick(function(){
		$(this).find("option:selected").each(function(){
			var s = isselected($(this).val());
			if (!s){
			    $(this).remove().appendTo(rightSel);

			}
		});
		update();
	});
	rightSel.dblclick(function(){
		$(this).find("option:selected").each(function(){
			$(this).remove().appendTo(leftSel);

		});
		update();
	});


});
</script>
</body>
</html>